<?php
/**
 * Created by PhpStorm.
 * User: xiaxiang
 * Date: 2019/4/20
 * Time: 17:56
 * 公共函数
 */


use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;

function mailto($to, $title, $content)
{
    $mail = new PHPMailer(true);
    try {
        //Server settings
        $mail->SMTPDebug = 0;// Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->CharSet    = 'utf-8';
        $mail->Host       = 'smtp.163.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth   = true;                               // Enable SMTP authentication
        $mail->Username   = 'm13012672386@163.com';                 // SMTP username
        $mail->Password   = 'xiaxiang1';                           // SMTP password
        $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port       = 465;                                    // TCP port to connect to

        //Recipients
        $mail->setFrom('m13012672386@163.com', '铭心旋律博客');
        $mail->addAddress($to);     // Add a recipient


        //Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $title;
        $mail->Body    = $content;

        return $mail->send();
    } catch (Exception $e) {
        \exception($mail->ErrorInfo, 1001);
    }
}

//字符串替换
function strReplace($value)
{
    return str_replace('span', 'a', $value);
}